﻿// ----------------------------------------------------------------------------------
// <copyright file="HomeController.cs" company="Christopher Hines">
// Copyright (c) 2012 All Right Reserved
// </copyright>
// <author>Chris Hines</author>
// <date>2012-03-23</date>
// <summary>
//     Home Controller
// </summary>
// ----------------------------------------------------------------------------------

namespace Copperfield.Demo.Web.Controllers
{
    using System.Web.Mvc;

    using Copperfield;
    using Copperfield.Demo.Common;

    /// <summary>
    /// Home Controller
    /// </summary>
    public partial class HomeController : Controller
    {
        #region Private Members

        /// <summary>
        /// Gets the context manager
        /// </summary>
        /// <value>
        /// The context manager
        /// </value>
        private readonly ContextManagerBase<SignContext> contextManager;

        #endregion

        #region Ctor

        /// <summary>
        /// Initializes a new instance of the <see cref="HomeController"/> class.
        /// </summary>
        /// <param name="contextManager">
        /// The context manager.
        /// </param>
        public HomeController(ContextManagerBase<SignContext> contextManager)
        {
            this.contextManager = contextManager;
        }

        #endregion

        /// <summary>
        /// Returns the Index View
        /// </summary>
        /// <returns>
        /// The Index View
        /// </returns>
        public virtual ActionResult Index()
        {
            var context = this.contextManager.GetContext() ?? new SignContext();
            
            return this.View(context);
        }

        /// <summary>
        /// Process a SignContext from the Index View
        /// </summary>
        /// <param name="signContext">
        /// The sign context.
        /// </param>
        /// <returns>
        /// The result of the action
        /// </returns>
        [HttpPost]
        public virtual ActionResult Index(SignContext signContext)
        {
            this.contextManager.SetContext(signContext ?? new SignContext());

            return this.RedirectToAction(MVC.Sign.Index());
        }
    }
}
